//
//  RecordsOfConsumptionViewController.m
//  EasyToTesco
//
//  Created by ym on 16/3/27.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "RecordsOfConsumptionViewController.h"
#import "AFNetworking.h"
#import "ReadLoginData.h"
@interface RecordsOfConsumptionViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, copy)NSString *username;
@property (nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation RecordsOfConsumptionViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)data{
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSString *username = _username;
    
    NSDictionary *param = @{@"username":[NSString stringWithFormat:@"%@", username]};
    
    [mgr POST:@"http://www.ylgw8.com/AppHz/Gethz " parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"---------%@", responseObject);
        NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        
  //      NSLog(@"Oilord--%@", string);
        
        //  石油订单
//        self.OilorderArray = [self toArrayOrNSDictionary:responseObject];
        
        self.dataArr = [self toArrayOrNSDictionary:responseObject];
        
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation,NSError *error)
     {
         //         operation.response.statusCode;//404 401之类
  //       NSLog(@"error:%@", error);
     //    NSLog(@"errorcode:%ld", (long)operation.response.statusCode);
     }];

}

- (void)getdata {
    // 获取当前账号
    NSDictionary *dic = [ReadLoginData readLoginData];
    if (dic.allKeys.count == 0) {
        UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您尚未登录,请登录后再次操作" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alview show];
    }else {
   //     usernameStr = [dic[@"data"] objectForKey:@"username"];
    }
    
}

     // 将JSON串转化为字典或者数组
     - (id)toArrayOrNSDictionary:(NSData *)jsonData{
         NSError *error = nil;
         id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
                                                         options:NSJSONReadingAllowFragments
                                                           error:&error];
         
         if (jsonObject != nil && error == nil){
             return jsonObject;
         }else{
             // 解析错误
             return nil;
         }
     }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
